<?php 
session_start();
if(!ob_start("ob_gzhandler")) ob_start();
?>
<html>
	<head>
		<title></title>
		<link rel = 'stylesheet' type = 'text/css' href = 'mainFrame.css'>
		<link rel = 'stylesheet' type = 'text/css' href = 'leftFrameStyle.css'>
		<script type='text/javascript' src='jquery-1.7.js'></script>
		<script type = 'text/javascript' src = 'jquery-ui-1.8.16.custom.min.js'></script>
		<link rel = "stylesheet" type = "text/css" href = "jquery-ui-1.8.18.custom.css">
	</head>
	<body>
	<?php 
        mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7")or die ("Problem with datebase");
	mysql_select_db("sapmenet_users");

	if (isset($_SESSION['JID']))
	{
		$userID=$_SESSION['JID'];
		$currentID=$_SESSION['id'];
		if ($userID!=$currentID)
		{
			$id=$_SESSION['id'];
			echo "<div id = 'leftFrameDiv'>
		<div id = 'name'>";
			
				$user=mysql_query("SELECT concat(FirstName,' ',LastName) AS FullName FROM users WHERE ID=$id");
				$userName=mysql_result($user, 0);
				echo ("<div id = 'name2'>".$userName."<img src='Icons/opened.png' id='triangleIcon'></div>");
				

			
		echo "</div>
		<div id = 'profilePicture'>";
		
		$mainPic=mysql_query("SELECT mainPic FROM users WHERE ID=$id");
		$mainPic=mysql_result($mainPic, 0);
		$_SESSION['mainPic']=$mainPic;
		//if (mysql_num_rows($mainPic)==0)
		if ($mainPic!='asd')
		{
			
			echo ("<div><img src='$mainPic'></div>");
		}
		else 
		{
			$sex=mysql_query("SELECT Sex FROM users WHERE ID=$id");
			$sex=mysql_result($sex, 0);
			if ($sex=='Male')
			{
				echo ("<img src='defaultProfileMale.jpg'>");
				$_SESSION['mainPic']="defaultProfileMale.jpg";
				
			}
			else 
			{
				echo ("<img src='defaultProfileFemale.jpg'>");
				$_SESSION['mainPic']="defaultProfileFemale.jpg";
			}
		}
		$fr=mysql_query("SELECT confirmed FROM friendships WHERE userID={$_SESSION['JID']} AND friendID={$_SESSION['id']}");
		if (mysql_num_rows($fr)<1)
		{
			
		}
		else{
		$fr=mysql_result($fr,0);
		if ($fr){
		
		
		echo "</div>
		<div id = 'buttons'>
			<div id = 'albumes' class = 'theButtons'>
				<img src = 'Icons/albums_icon_large.png' class = 'leftIcons'> Albums
			</div>
			<div id='information' class='theButtons'>
				<img src='Icons/info.gif' class='leftIcons'> Info
			</div>
			<div id = 'friends' class = 'theButtons'>
				<img src = 'Icons/drunk.gif' class = 'leftIcons'> Friends
			</div>
			<div id = 'games' class = 'theButtons'>
				<img src = 'games.gif' class = 'leftIcons'> Games
			</div>
		</div>
	</div>
	<script>
		$('#albumes').click(function()
		{
			$('#mainFrame').load('albums.php');
			$(this).effect('shake', {times:1, distance:7}, 256);
		});
		$('#information').click(function()
		{
			$('#mainFrame').load('information.php');
			$(this).effect('shake', {times:1, distance:7}, 256);
		});
		$('#friends').click(function()
		{
			$('#mainFrame').load('friends.php');
			$(this).effect('shake', {times:1, distance:7}, 256);
		});
		$('#games').click(function()
		{
			$('#mainFrame').load('games.php');
			$(this).effect('shake', {times:1, distance:7}, 256);
		});
	</script>";
	}
	else 
		{
			//ako ne ste fr.
		}
		}
		}
		
	
	else {
	echo "<div id = 'leftFrameDiv'>
		<div id = 'name'>";
			
				$user=mysql_query("SELECT concat(FirstName,' ',LastName) AS FullName FROM users WHERE email LIKE '".$_SESSION['user']."'");
				$userName=mysql_result($user, 0);
				echo ("<div id='name2'>".$userName."<img src='Icons/opened.png' id='triangleIcon'></div>");
				

			
		echo "</div>
		<div id = 'profilePicture'>";
		$mainPic=mysql_query("SELECT mainPic FROM users WHERE email LIKE '".$_SESSION['user']."'");
		$mainPic=mysql_result($mainPic, 0);
		//if (mysql_num_rows($mainPic)==0)
		if ($mainPic!='asd')
		{
			
			echo ("<div><img src='$mainPic'></div>");
		}
		else 
		{
			$sex=mysql_query("SELECT Sex FROM users WHERE email LIKE '".$_SESSION['user']."'");
			$sex=mysql_result($sex, 0);
			if ($sex=='Male')
			{
				echo ("<img src='defaultProfileMale.jpg'>");
			}
			else 
			{
				echo ("<img src='defaultProfileFemale.jpg'>");
			}
		}
		echo "</div>
		<div id = 'buttons'>
			<div id = 'albumes' class = 'theButtons'>
				<img src = 'Icons/albums_icon_large.png' class = 'leftIcons'> Albums
			</div>
			<div id = 'settings' class = 'theButtons'>
				<img src = 'Icons/Categories-preferences-system-icon.gif' class = 'leftIcons'> Settings
			</div>
			<div id = 'friends' class = 'theButtons'>
				<img src = 'Icons/drunk.gif' class = 'leftIcons'> Friends
			</div>
			<div id = 'games' class = 'theButtons'>
				<img src = 'games.gif' class = 'leftIcons'> Games
			</div>
		</div>
	</div>
	<script>
		$('#albumes').click(function()
		{
			$('#mainFrame').load('albums.php');
			$(this).effect('shake', {times:1, distance:7}, 256);
		});
		$('#settings').click(function()
		{
			$('#mainFrame').load('settings.php');
			$(this).effect('shake', {times:1, distance:7}, 256);
		});
		$('#friends').click(function()
		{
			$('#mainFrame').load('friends.php');
			$(this).effect('shake', {times:1, distance:7}, 256);
		});
		$('#games').click(function()
		{
			$('#mainFrame').load('games.php');
			$(this).effect('shake', {times:1, distance:7}, 256);
		});
	</script>";
	}
	}
	else{
		header ('Location: ..\index.php');
		exit();
	}
        ?>
		<center>
			<div id='bym'>
				<div id='sapped' class='act'>Sap</div>
				<div id='kicked' class='act'>Kick</div>
				<div id='kissed' class='act'>Kiss</div>
				<div id='fucked' class='act'>Fuck</div>
				<div id='hitted' class='act'>Hit</div>
				<div id='spitted' class='act'>Spit</div>
				<div id='nipped' class='act'>Nip</div>
				<div id='hugged' class='act'>Hug</div>
				<div id='killed' class='act'>Kill</div>
				<div id='beat' class='act'>Beat</div>
			</div>
		</center>
	</body>
		<script>
			var clicked=false;
			$("#bym").draggable("destroy");
			$('#name').click(function()
			{
				if (!clicked)
				{
					
					$("#bym").show("blind",{direction:"horizontal"});
					$("#triangleIcon").attr("src", "Icons/closed.png");
					clicked = true;
					
				}
				else
				{
					$("#bym").hide("blind");
					$("#triangleIcon").attr("src", "Icons/opened.png");
					clicked = false;
					
				}
				
			});
			$(".act").click(function()
			{
				$(".act").removeClass('tikvichka');
				$(this).addClass('tikvichka');
				var dd = $('.tikvichka').attr('id');
				$.post('action.php',{action: dd} , function()
				{
					$("#bym").hide("blind");
					$("#triangleIcon").attr("src", "Icons/opened.png");
					clicked = false;
				});
			});
			
		</script>
		
	
     </html>